package cn.lzit.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

@WebServlet(name = "OrderServlet", urlPatterns = "/order")

public class OrderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        String foodName[]=request.getParameterValues("check");
        if(foodName!=null){
            for(int k=0;k<foodName.length;k++){
                request.getSession().setAttribute(foodName[k], foodName[k]);
            }
        }
        String url = "<a href='/cart'>欢迎去购物车页面！</a>";
        response.getWriter().print("<p>点击超链接，链接到购物车页面，去查看购物车中的商品。</br>"+url);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
